package com.codedancer.campus.manager.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.manager.service.ILostFoundItemExamineRecordService;
import com.codedancer.campus.manager.service.vo.lostFoundItem.LostFoundItemExamineRecordVo;
import com.codedancer.campus.mapper.AdminMapper;
import com.codedancer.campus.mapper.LostFoundItemExamineRecordMapper;
import com.codedancer.campus.po.Admin;
import com.codedancer.campus.po.LostFoundItemExamineRecord;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class LostFoundItemExamineRecordServiceImpl implements ILostFoundItemExamineRecordService {

    @Autowired
    private LostFoundItemExamineRecordMapper lostFoundItemExamineRecordMapper;
    @Autowired
    private AdminMapper adminMapper;

    /**
     * 查询失物招领审核记录
     *
     * @param lostFoundItemUuid
     * @return
     */
    @Override
    public List<LostFoundItemExamineRecordVo> list(String lostFoundItemUuid) {
        List<LostFoundItemExamineRecord> lostFoundItemExamineRecords = lostFoundItemExamineRecordMapper
            .list(lostFoundItemUuid);
        return lostFoundItemExamineRecords.stream().map(lostFoundItemExamineRecord -> {
            LostFoundItemExamineRecordVo lostFoundItemExamineRecordVo = BeanUtil
                .copyProperties(lostFoundItemExamineRecord, LostFoundItemExamineRecordVo.class);
            Admin admin = adminMapper.selectById(lostFoundItemExamineRecord.getExamineAdminUuid());
            lostFoundItemExamineRecordVo.setExamineAdminName(admin.getLoginName());
            return lostFoundItemExamineRecordVo;
        }).collect(Collectors.toList());
    }
}
